<?php

namespace Home\Model;

use Think\Model;

class CashsModel extends Model
{
    protected $autoCheckFields = false;
    private $user;
    private $isbn;
    private $typs;
    private $stat;

    public function gettypes($u, $i, $t, $status)
    {
        $this->user = $u;
        $this->isbn = $i;
        $this->typs = $t;
        $this->stat = $status;
        return $this->loadsel();
    }

    private function loadsel()
    {
        switch ($this->typs) {
            case '21': return $this->loadparts();
                break;
            case '23': return $this->loadparts();
                break;
            case '2301': return $this->loadfulls();
                break;
            case '2302': return $this->loadfulls();
                break;
        }
    }

    //Part 21,23
    private function loadparts()
    {
        $settlement = M('settlement');
        $prev = $settlement->where("set_ssaid=" . $this->user["ssa_id"])->order("set_id desc")->find();
        $where["c_disid"] = $this->isbn["dis_id"];
        $where["c_status"] = $this->stat;
        $where["c_month"] = array($this->stat==1?"gt":"elt", $prev["set_month"]);
        return $where;
    }
    
    //Part 2301,2302
    private function loadfulls()
    {
        $settlement = M('settlement');
        $prev = $settlement->where("set_agent=" . $this->user["sag_id"])->order("set_id desc")->find();
        $where["c_agent"] = $this->user["sag_id"];
        $where["c_status"] = $this->stat;
        $where["c_month"] = array($this->stat==1?"gt":"elt", $prev["set_month"]);
        return $where;
    }
}
